package com.msstudio.i18n;

// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Hashtable;

public class Local {//���显示字符串定义，所有要显示的字符串必须放在这里

    private static Local loc = null;
    /* public static final short I18N_TMSC = 0;
    public static final short I18N_STIMEOUT = 1;
    public static final short I18N_SWRONG = 2;
    public static final short I18N_INST = 3;
    public static final short I18N_HELPMSG = 4;
    public static final short I18N_ADDFAIL = 5;
    public static final short QTJ_KQQ_ADDFRIEND = 6;
    public static final short QTJ_KQQ_ADDSUCCEED = 7;
    public static final short QTJ_KQQ_ADDTOBLACKLIST = 8;
    public static final short QTJ_KQQ_ADDTOFRIENDLIST = 9;
    public static final short QTJ_KQQ_ADDUFRIEND = 10;
    public static final short QTJ_KQQ_AGREE = 11;
    public static final short QTJ_KQQ_ALLFRIEND = 12;
    public static final short QTJ_KQQ_ALREADYBEURFRIEND = 13;
    public static final short QTJ_KQQ_ANSWER = 14;
    public static final short QTJ_KQQ_ASKUPASS7 = 15;
    public static final short QTJ_KQQ_ATTACHMESSAGE = 16;
    public static final short QTJ_KQQ_BACK = 17;
    public static final short QTJ_KQQ_BLACKLIST = 18;
    public static final short QTJ_KQQ_CANCEL = 19;
    public static final short QTJ_KQQ_CANNOTSENDNULL = 20;
    public static final short QTJ_KQQ_CHANGESTAT = 21;
    public static final short QTJ_KQQ_CHECKBLACKLIST = 22;
    public static final short QTJ_KQQ_CONTINUE = 23;
    public static final short QTJ_KQQ_CURFRIEND = 24;
    public static final short QTJ_KQQ_DELETE = 25;
    public static final short QTJ_KQQ_DELETEFRIEND = 26;
    public static final short QTJ_KQQ_DELETESUCCEED = 27;
    public static final short QTJ_KQQ_DETAILINFOR = 28;
    public static final short QTJ_KQQ_DETAILS = 29;
    public static final short QTJ_KQQ_EXIT = 30;
    public static final short QTJ_KQQ_FEMALE = 31;
    public static final short QTJ_KQQ_FINGER = 32;
    public static final short QTJ_KQQ_FLOWCONTROLOFF = 33;
    public static final short QTJ_KQQ_FLOWCONTROLON = 34;
    public static final short QTJ_KQQ_GETINFOR = 35;
    public static final short QTJ_KQQ_HELP = 36;
    public static final short QTJ_KQQ_HISTORY = 37;
    public static final short QTJ_KQQ_HISTORYISNULL = 38;
    public static final short QTJ_KQQ_INST = 39;
    public static final short QTJ_KQQ_INVALIDQQNO = 40;
    public static final short QTJ_KQQ_INVISIBLE = 41;
    public static final short QTJ_KQQ_LEAVE = 42;
    public static final short QTJ_KQQ_LOGIN = 43;
    public static final short QTJ_KQQ_LOGINFAIL = 44;
    public static final short QTJ_KQQ_LOGINFAILMSG = 45;
    public static final short QTJ_KQQ_LOGINFORM = 46;
    public static final short QTJ_KQQ_LOGINING = 47;
    public static final short QTJ_KQQ_LOGINMSGDELETED = 48;
    public static final short QTJ_KQQ_MALE = 49;
    public static final short QTJ_KQQ_MENUADDTOFRIENDLIST = 50;
    public static final short QTJ_KQQ_MENUGETINFOR = 51;
    public static final short QTJ_KQQ_MENUHISTORY = 52;
    public static final short QTJ_KQQ_MENUSENDMESSAGE = 53;
    public static final short QTJ_KQQ_NEEDCERTIFICATE = 54;
    public static final short QTJ_KQQ_NETCONNECTFAILMSG = 55;
    public static final short QTJ_KQQ_NETERROR = 56;
    public static final short QTJ_KQQ_NETERRORMSG = 57;
    public static final short QTJ_KQQ_NEWMESSAGE = 58;
    public static final short QTJ_KQQ_NEXT = 59;
    public static final short QTJ_KQQ_OK = 60;
    public static final short QTJ_KQQ_ONLINE = 61;
    public static final short QTJ_KQQ_ONLINEFRIEND = 62;
    public static final short QTJ_KQQ_OPTIONS = 63;
    public static final short QTJ_KQQ_PASSEDUCERTIFICATE = 64;
    public static final short QTJ_KQQ_PRE = 65;
    public static final short QTJ_KQQ_PROVINCE_AH = 66;
    public static final short QTJ_KQQ_PROVINCE_BJ = 67;
    public static final short QTJ_KQQ_PROVINCE_CQ = 68;
    public static final short QTJ_KQQ_PROVINCE_FJ = 69;
    public static final short QTJ_KQQ_PROVINCE_GD = 70;
    public static final short QTJ_KQQ_PROVINCE_GS = 71;
    public static final short QTJ_KQQ_PROVINCE_GX = 72;
    public static final short QTJ_KQQ_PROVINCE_GZ = 73;
    public static final short QTJ_KQQ_PROVINCE_HAIN = 74;
    public static final short QTJ_KQQ_PROVINCE_HB = 75;
    public static final short QTJ_KQQ_PROVINCE_HK = 76;
    public static final short QTJ_KQQ_PROVINCE_HLJ = 77;
    public static final short QTJ_KQQ_PROVINCE_HN = 78;
    public static final short QTJ_KQQ_PROVINCE_HUB = 79;
    public static final short QTJ_KQQ_PROVINCE_HUN = 80;
    public static final short QTJ_KQQ_PROVINCE_JL = 81;
    public static final short QTJ_KQQ_PROVINCE_JS = 82;
    public static final short QTJ_KQQ_PROVINCE_JX = 83;
    public static final short QTJ_KQQ_PROVINCE_LN = 84;
    public static final short QTJ_KQQ_PROVINCE_MA = 85;
    public static final short QTJ_KQQ_PROVINCE_NM = 86;
    public static final short QTJ_KQQ_PROVINCE_NX = 87;
    public static final short QTJ_KQQ_PROVINCE_QH = 88;
    public static final short QTJ_KQQ_PROVINCE_SC = 89;
    public static final short QTJ_KQQ_PROVINCE_SD = 90;
    public static final short QTJ_KQQ_PROVINCE_SH = 91;
    public static final short QTJ_KQQ_PROVINCE_SHX = 92;
    public static final short QTJ_KQQ_PROVINCE_SX = 93;
    public static final short QTJ_KQQ_PROVINCE_TJ = 94;
    public static final short QTJ_KQQ_PROVINCE_TW = 95;
    public static final short QTJ_KQQ_PROVINCE_XJ = 96;
    public static final short QTJ_KQQ_PROVINCE_XZ = 97;
    public static final short QTJ_KQQ_PROVINCE_YN = 98;
    public static final short QTJ_KQQ_PROVINCE_ZJ = 99;
    public static final short QTJ_KQQ_QQHELP = 100;
    public static final short QTJ_KQQ_QQNO = 101;
    public static final short QTJ_KQQ_QQPASSWORD = 102;
    public static final short QTJ_KQQ_READMESSAGE = 103;
    public static final short QTJ_KQQ_REFUSE = 104;
    public static final short QTJ_KQQ_REFUSEDUCERTIFICATE = 105;
    public static final short QTJ_KQQ_REFUSETOBEADDED = 106;
    public static final short QTJ_KQQ_RELOGIN = 107;
    public static final short QTJ_KQQ_REMOVELOGININFOR = 108;
    public static final short QTJ_KQQ_RESEARCHRESULT = 109;
    public static final short QTJ_KQQ_SELECTAGE = 110;
    public static final short QTJ_KQQ_SELECTPROVINCE = 111;
    public static final short QTJ_KQQ_SELECTSEX = 112;
    public static final short QTJ_KQQ_SEND = 113;
    public static final short QTJ_KQQ_SENDED = 114;
    public static final short QTJ_KQQ_SENDFAIL = 115;
    public static final short QTJ_KQQ_SENDMESSAGE = 116;
    public static final short QTJ_KQQ_SLOGOUT = 117;
    public static final short QTJ_KQQ_START = 118;
    public static final short QTJ_KQQ_STRANGER = 119;
    public static final short QTJ_KQQ_SYSMESSAGEMENU = 120;
    public static final short QTJ_KQQ_SYSTEMMESSAGE = 121;
    public static final short QTJ_KQQ_TITLE_OPTIONS = 122;
    public static final short QTJ_KQQ_UHAVENOFRIEND = 123;
    public static final short QTJ_KQQ_URBLFULL = 124;
    public static final short QTJ_KQQ_URBLNULL = 125;
    public static final short QTJ_KQQ_WAITMSG = 126;
    public static final short QTJ_KQQ_YESTODELETE = 127;
    public static final short QTJ_KQQ_YESTOEXIT = 128;
    public static final short QTJ_KQQ_YESTORECOVER = 129; */
    
    public static final String phoneLang = System.getProperty("microedition.locale");
    public static Hashtable i18nResources = null;

    private Local() {
    }

    private static String replace(String s, String s1, String s2) {
        int i = s.indexOf(s1);
        return i < 0 ? s : s.substring(0, i) + s2 + s.substring(i + s1.length());
    }

    public static synchronized String getText(String str) {
        //return getText(i, null);
        Object value = i18nResources.get(str);
        if (value == null) {
            return str + "is missing from i18n!";
        }
        return value.toString();
    }

    public static synchronized String getText(int i, String as[]) {
        InputStream inputstream;
        if (loc == null) {
            loc = new Local();
        }
        // http://wenku.baidu.com/view/4c009df7f61fb7360b4c65cf.html
        inputstream = loc.getClass().getResourceAsStream("/lang." + phoneLang);
        if (inputstream == null) {
            inputstream = loc.getClass().getResourceAsStream("/lang.xx");
        }
        if (inputstream == null) {
            return "NoLang";
        }
        String s = "";
        DataInputStream datainputstream = new DataInputStream(inputstream);
        try {
            datainputstream.skipBytes(i * 2);
            short word0 = datainputstream.readShort();
            datainputstream.skipBytes(word0 - i * 2 - 2);
            s = datainputstream.readUTF();
        } catch (Exception ex) {
        }
        if (datainputstream != null) {
            try {
                datainputstream.close();
            } catch (Exception ex) {
            }
        }
        if (as != null) {
            if (as.length == 1) {
                s = replace(s, "%U", as[0]);
            } else {
                for (int j = 0; j < as.length; j++) {
                    s = replace(s, "%" + j + "U", as[j]);
                }
            }
        }

        return s;
    }

    public static void loadI18nFromTxtFile(String fileName) {
        i18nResources = new Hashtable();
        String encodeStr = "UTF-8";
        if (loc == null) {
            loc = new Local();
        }
        // http://wenku.baidu.com/view/4c009df7f61fb7360b4c65cf.html
        String fullFileName = "/" + fileName + "." + phoneLang;
        InputStream is = loc.getClass().getResourceAsStream(fullFileName);
        ByteArrayOutputStream key = new ByteArrayOutputStream();
        ByteArrayOutputStream value = new ByteArrayOutputStream();
        int c = 0;
        boolean isValue = false;

        try {
            while ((c = is.read()) != -1) {
                if (c == '=') {
                    isValue = true;
                    continue;
                }
                if (c == '\n' || c == '\r') {
                    if (key.size() != 0) {            
                        i18nResources.put(new String(key.toByteArray(), encodeStr),
                                new String(value.toByteArray(), encodeStr));
                    }
                    key.reset();
                    value.reset();
                    isValue = false;
                    continue;
                }
                if (isValue) {
                    value.write(c);
                } else {
                    key.write(c);
                }
            } //while ((c=is.read() != -1))
            if (key.size() != 0 ) {     //如果最后一行不以\r或者\n结尾，也要写入          
                i18nResources.put(new String(key.toByteArray(), encodeStr),
                        new String(value.toByteArray(), encodeStr));
            }
        } catch (IOException e) {
            System.out.println("failed to load:" + e.getMessage());
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (Exception ex) {
                }
            }
            if (key != null) {
                try {
                    key.close();
                } catch (Exception ex) {
                }
            }
            if (value != null) {
                try {
                    value.close();
                } catch (Exception ex) {
                }
            }
        }
    }
}
